/*    */ package handling.netty;
/*    */ 
/*    */ import handling.ServerType;
/*    */ import io.netty.bootstrap.ServerBootstrap;
/*    */ import io.netty.channel.Channel;
/*    */ import io.netty.channel.ChannelHandler;
/*    */ import io.netty.channel.ChannelOption;
/*    */ import io.netty.channel.EventLoopGroup;
/*    */ import io.netty.channel.nio.NioEventLoopGroup;
/*    */ import io.netty.channel.socket.nio.NioServerSocketChannel;
/*    */ 
/*    */ public class ServerConnection
/*    */ {
/*    */   private final int port;
/* 15 */   private final EventLoopGroup bossGroup = (EventLoopGroup)new NioEventLoopGroup(1);
/* 16 */   private final EventLoopGroup workerGroup = (EventLoopGroup)new NioEventLoopGroup();
/*    */   private final ServerType type;
/* 18 */   private int world = -1;
/* 19 */   private int channels = -1;
/*    */   private ServerBootstrap boot;
/*    */   private Channel channel;
/*    */   
/*    */   public ServerConnection(int port, int world, int channels, ServerType type) {
/* 24 */     this.port = port;
/* 25 */     this.world = world;
/* 26 */     this.channels = channels;
/* 27 */     this.type = type;
/*    */   }
/*    */   
/*    */   public void run() {
/*    */     try {
/* 32 */       this
/*    */ 
/*    */ 
/*    */ 
/*    */         
/* 37 */         .boot = ((ServerBootstrap)((ServerBootstrap)(new ServerBootstrap()).group(this.bossGroup, this.workerGroup).channel(NioServerSocketChannel.class)).option(ChannelOption.SO_BACKLOG, Integer.valueOf(1000))).childOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true)).childOption(ChannelOption.SO_KEEPALIVE, Boolean.valueOf(true)).childHandler((ChannelHandler)new ServerInitializer(this.world, this.channels, this.type));
/*    */       
/* 39 */       this.channel = this.boot.bind(this.port).sync().channel().closeFuture().channel();
/* 40 */       System.out.printf("正在启动 - %s 端口: %s\r\n", new Object[] { this.type.name(), Integer.valueOf(this.port) });
/* 41 */     } catch (Exception e) {
/* 42 */       throw new RuntimeException("启动失败 - " + this.type.name() + ":" + this.channel.remoteAddress());
/*    */     } 
/*    */   }
/*    */   
/*    */   public void close() {
/* 47 */     this.channel.close();
/* 48 */     this.bossGroup.shutdownGracefully();
/* 49 */     this.workerGroup.shutdownGracefully();
/*    */   }
/*    */ }


/* Location:              C:\PGX\Server.jar!\handling\netty\ServerConnection.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */